/***************************************************************************************************
  Copyright(C)   2011-2013
  All rights reserved.
  File Name: serverwidget.h

  Description:网络服务端模块，主要处理维护器(MaintenanceTerminal)的一切网络请求


  ***************************************************************************************************/

#ifndef SERVERWIDGET_H
#define SERVERWIDGET_H

#include <QtGui/QWidget>
#include <QPushButton>
#include <QTextEdit>
#include <QLineEdit>
#include <QLabel>
#include <QProcess>
#include <QTimer>
#include <QDialog>
#include <QHostInfo>
#include <QCloseEvent>

#include "tcpserver.h"
#include "manageprocess.h"
#include "usb/updateresource.h"
#include "public/configclass.h"
#include "serialctlthread.h"
#include "log.h"
#include "update/updateserver.h"

#ifdef _TTY_POSIX_
#include "examinition/examinitionthread.h"
#endif

extern QString g_installPath;

#define PROGRAMCEPATHBACKUP  g_installPath + "/back/program"



class ServerWidget : public QDialog
{
    Q_OBJECT
    LOG4QT_DECLARE_QCLASS_LOGGER

public:
    ServerWidget(int state = 0, QWidget *parent = 0);
    ~ServerWidget();


    void init();
    void startDisplayClient();

protected:
    void closeEvent(QCloseEvent *);

signals:
    void updateConfig();
    void systemState(const SystemState&);
    void sendVideoStatus(const QList<LCDSTATUS>& status, const bool isSendToTis);
    void receCheckLcdCmd(const qint8 cmd);      //收到检测LCD屏的命令


private:
    TcpServer       *tcpServer;
    SerialCtlThread *m_serialCtlThread;
    QCloseEvent     *event;
    Configclass     configClass;

    QTimer closeTimer;
    QTimer *processTimer;

#ifdef _TTY_POSIX_
    ExaminitionThread *m_examThread;
#endif

//    QPushButton *emtButton;
//    QTextEdit *textEdit;
//    QLineEdit *lineEdit;

    ManageProcess *manageProcess;

    bool isUpdateSuccess;

    int serviceState;               //服务端状态，0：第一次运行 1：更新成功 2，更新失败
    QTimer *dogTimer;

private slots:
    void receFeedData(const FreedDogStruct& freedDogStruct);
//    void updateService(const int state, const int fileCount);
    void receUpdateFile(const int state, const int fileCount);

    void receDubMsg(const QString& msg);
    void dogTimeOut();
    void receSensorData(const qint16);
    void receSysState(const SystemState sysState);

    void closeWidget();

    void checkVidoStatu();

    void receUpdateStateSlot(const int state);


};

#endif // SERVERWIDGET_H
